<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../layui/css/layui.css" media="all">

  <title>Document</title>

  <style>
    .layui-table-cell {
      height: 60px;
      line-height: 60px;
      /* height: auto !important;
      white-space: normal;
      padding: 0px; */
    }

    th .layui-table-cell {
      height: 30px;
      line-height: 30px;
    }

    th .laytable-cell-1-0-7 {
      height: 30px;
      line-height: 30px;
    }

    .layui-table img {
      width: 100px;
      height: 60px;
    }
  </style>

</head>

<body>
  <legend>搜索信息</legend>
  <div style="margin: 10px 10px 10px 10px">
    <form class="layui-form layui-form-pane" action="">
      <div class="layui-form-item">

        <div class="layui-inline">
          <label class="layui-form-label">职工号</label>
          <div class="layui-input-inline">
            <input type="text" name="vwnoid" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">职工姓名</label>
          <div class="layui-input-inline">
            <input type="text" name="vwonname" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">请假日期</label>
          <div class="layui-input-inline">
            <input type="date" name="vdate" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">请假天数</label>
          <div class="layui-input-inline">
            <input type="text" name="vleavedays" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">请假原因</label>
          <div class="layui-input-inline">
            <input type="text" name="vleavecause" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">批准人</label>
          <div class="layui-input-inline">
            <input type="text" name="vapprover" autocomplete="off" class="layui-input">
          </div>
        </div>
        <div class="layui-inline">
          <button type="submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="data-search-btn"><i
              class="layui-icon"></i> 搜 索</button>
        </div>
      </div>
    </form>
  </div>

  <table class="layui-hide" id="test" lay-filter="test"></table>

  <script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
      <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
      <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
      <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
   </div>
  </script>

  <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


  <script src="../layui/layui.js" charset="utf-8"></script>
  <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

  <script>
    layui.use('table', function () {
      var table = layui.table,
        form = layui.form,
        $ = layui.jquery;
      table.render({
        elem: '#test'
        , url: 'http://localhost:8080/vacation/pageData'/*tpa=https://www.layuiweb.com/test/table/demo1.json*/
        /*,url:'/json/demo2.json'*/
        , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
        , defaultToolbar: ['f2ilter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
          title: '提示'
          , layEvent: 'LAYTABLE_TIPS'
          , icon: 'layui-icon-tips'
        }]
        , title: '用户数据表'
        , contentType: "application/x-www-form-urlencoded"
        , cols: [[
          { type: 'checkbox', fixed: 'left' }
          , { field: 'vwnoid', title: '职工号', width: 120, edit: 'text' }
          , { field: 'vwonname', title: '职工姓名', width: 120, edit: 'text' }
          , { field: 'vdate', title: '请假日期', width: 100 }
          , { field: 'vleavedays', title: '请假天数', width: 80 }
          , { field: 'vleavecause', title: '请假原因', sort: true }
          , { field: 'vapprover', title: '批准人', width: 100, sort: true }
          , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200 }
        ]]
        , page: true
      });

      // 监听搜索操作
      form.on('submit(data-search-btn)', function (data) {
        var result = JSON.stringify(data.field);
        layer.alert(result, {
          title: '最终的搜索信息'
        });

        //执行搜索重载
        table.reload('test', {
          page: {
            curr: 1
          }
          , where: {
            "vwnoid": data.field.vwnoid,
            "vwonname": data.field.vwonname,
            "vdate": data.field.vdate,
            "vleavedays": data.field.vleavedays,
            "vleavecause": data.field.vleavecause,
            "vapprover": data.field.vapprover
          }
        }, 'data');

        return false;
      });



      //头工具栏事件
      table.on('toolbar(test)', function (obj) {
        var checkStatus = table.checkStatus(obj.config.id);
        switch (obj.event) {
          case 'getCheckData':
            var data = checkStatus.data;
            layer.alert(JSON.stringify(data));
            break;
          case 'getCheckLength':
            var data = checkStatus.data;
            layer.msg('选中了：' + data.length + ' 个');
            break;
          case 'isAll':
            layer.msg(checkStatus.isAll ? '全选' : '未全选');
            break;

          case 'add':
            layer.open({
              title: '添加用户',
              shade: 0.2,
              type: 2,
              shadeClose: true,   // 点别的地方 是否关闭当前 layer    true收关闭   false 不关闭
              area: ['80%', '100%'],
              fixed: true, //不固定
              maxmin: true,
              content: 'adduser.html',
              end: function (index) {
                table.reload('test');
              }
            });

            break;

          //自定义头工具栏右侧图标 - 提示
          case 'LAYTABLE_TIPS':
            layer.alert('这是工具栏右侧自定义的一个图标按钮');
            break;
        };
      });

      //监听行工具事件
      table.on('tool(test)', function (obj) {
        var data = obj.data;
        //console.log(obj)
        if (obj.event === 'del') {
          layer.confirm('真的删除行么', function (index) {
            $.ajax({
              "url": "http://localhost:8080/vacation/delete",
              "data": {
                "id": data.id
              },
              "success": function (result) {
                if (result.code == 200) {
                  layer.msg("删除成功");
                  obj.del();
                } else {
                  layer.msg("删除失败");
                }
              }
            });

            layer.close(index);


          });
        } else if (obj.event === 'edit') {
          // layer.prompt({
          //   formType: 2
          //   ,value: data.email
          // }, function(value, index){
          //   obj.update({
          //     email: value
          //   });
          //   layer.close(index);
          // });

          localStorage.setItem("user", JSON.stringify(data));  // 把数据存到 localStorage  

          layer.open({
            title: '编辑用户',
            shade: 0.2,
            type: 2,
            shadeClose: true,   // 点别的地方 是否关闭当前 layer    true关闭   false 不关闭
            area: ['80%', '100%'],
            fixed: true, //不固定
            maxmin: true,
            content: './useredit.html',
            end: function (index) {
              table.reload('test');
            }
          });

        }
      });
    });
  </script>
</body>

</html>